/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.pub.service;

import javacommon.base.BaseManager;
import javacommon.base.EntityDao;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;
import cn.org.rapid_framework.util.ObjectUtils;

import com.tech15.core.dao.SysUserDao;
import com.tech15.core.model.SysUser;
import com.tech15.pub.dao.MeetingAuthDao;
import com.tech15.pub.model.MeetingAuth;
import com.tech15.pub.vo.query.MeetingAuthQuery;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */

@Service
@Transactional
public class MeetingAuthManager extends BaseManager<MeetingAuth,Long>{

	private MeetingAuthDao meetingAuthDao;
	private SysUserDao sysUserDao;
	
	public void setSysUserDao(SysUserDao sysUserDao) {
		this.sysUserDao = sysUserDao;
	}
	public void setMeetingAuthDao(MeetingAuthDao dao) {
		this.meetingAuthDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.meetingAuthDao;
	}
	
	public MeetingAuth getById(Long id){
		MeetingAuth auth = meetingAuthDao.getById(id);
		if(ObjectUtils.isNotEmpty(auth.getUserid())){
			SysUser user = sysUserDao.getById(auth.getUserid());
			if(user != null){
				auth.setRealname(user.getRealname());
			}
		}
		return auth;
	}
	
	@Transactional(readOnly=true)
	public Page findPage(MeetingAuthQuery query) {
		return meetingAuthDao.findPage(query);
	}
	
	@Transactional(readOnly=true)
	public Page findByPageRequest(PageRequest pr) {
		return meetingAuthDao.findByPageRequest(pr);
	}
	public Integer getAuth(Long userid) {
		return meetingAuthDao.getCount("select count(*) from meeting_auth t where t.userid="+userid);
	}
	
}
